<?php
session_start();
// Include config file
require_once "registration_config.php";
require_once "registration_function.php";
date_default_timezone_set('Asia/Kolkata');


$current_date = date("Y-m-d");
$dateDisplay = date("d/m/Y", strtotime($current_date));
$day = date('l', strtotime($current_date));
//$day = date('D', strtotime($current_date)); // First Three digits of the day name
$current_time = date("H:i:s");



$institute = $_SESSION['institute'];
$address = $_SESSION['address'];
$purpose = $_SESSION['purpose'];


//echo $_SESSION['email'];

$name = $_SESSION['name'];
$email = $_SESSION['email'];
$reg_no = $_SESSION['reg_no'];
$reg_code = $_SESSION['reg_code'];
$mobile = $_SESSION['mobile'];
$motp = $_SESSION['motp'];
$p_mobile = $_SESSION['p_mobile'];
$potp = $_SESSION['potp'];
$board_id = $_SESSION['board_id'];
$school = 	$_SESSION['school'];
$board = 	$_SESSION['board'];

$file_pho =  $reg_no."_photo.jpg";

$conn = OpenCon();
			$sql = "SELECT * FROM applicants
					WHERE email = '$email'";
					
			$result = mysqli_query ($conn, $sql)or die(mysqli_error($conn));
			if (mysqli_affected_rows($conn) == 1) {
				$record = mysqli_fetch_array($result, MYSQLI_ASSOC);
				$photo=$record['photo'];
				$school=$record['school'];
				$board_id=$record['board_id'];
				$board = getValue('board', $board_id);
				$certificate_no=$record['certificate_no'];
				$division=$record['division'];
				$stream_id=$record['stream_id'];
				//if($stream_id > 0){
					//$stream = getValue('stream', $stream_id);
				//}
			}
CloseCon($conn);

// Define variables and initialize with empty values


$board_err = $stream_err="";

$message = "Edit your educational information.<br><br>Fields marked with <span  style='color:red'> *</span> are
			mandatory.<br><br>You must press <b>Update School Information</b> button to reflect the changes made 
			by you.<br><br> <b>NB:</b><br><br>
			कॉलेज और KC Support से संपर्क करने के समय आपको अपना <b>[Applicant Code: ".$reg_code."] </b>बताना जरूरी है।";
$note="";

$button = 1;

if($_SERVER["REQUEST_METHOD"] == "POST"){

$certificate_no = $_POST['certificate_no'];
$division = $_POST['division'];
$school = $_POST['school'];

//$_POST['board_id'];
	if(empty($_POST['board_id'])){
		$board_err = 'Select Board';
	}else {
		$board_id = $_POST['board_id'];
	}
	
	
	
	$school = AdjustApostopheS($school);
	$certificate_no = AdjustApostopheS($certificate_no);
	$division = AdjustApostopheS($division);
	$conn = OpenCon();
	if(empty($board_err)){
		
		$sql = "UPDATE applicants SET school = '$school', board_id = '$board_id', 
				stream_id ='$stream_id', certificate_no = '$certificate_no', division = '$division'
					WHERE reg_no = '$reg_no'";
		mysqli_query ($conn, $sql)or die(mysqli_error($conn));	
		$message = "Your previous school information have been updated. If you still want to change then make necessary
							changes	and press <b>Update School Information</b> button.<br><br>You can continue to update information until 
							you are satisfied and confirmed with information as displayed.";	
		//$_SESSION['message'] = 'Your Previous School information has been updated.';
		//echo "<script type='text/javascript'> document.location = '04_applicant_menu.php'; </script>";
	}

	$sql = "SELECT * FROM applicants
					WHERE email = '$email'";
					
	$result = mysqli_query ($conn, $sql)or die(mysqli_error($conn));
	if (mysqli_affected_rows($conn) == 1) {
		$record = mysqli_fetch_array($result, MYSQLI_ASSOC);
		$photo=$record['photo'];
		$school=$record['school'];
		$board_id=$record['board_id'];
		$board = getValue('board', $board_id);
		$certificate_no=$record['certificate_no'];
		$division=$record['division'];
		$stream_id=$record['stream_id'];
		//if($stream_id > 0){
			//$stream = getValue('stream', $stream_id);
		//}
	}	
	CloseCon($conn);
}
?>
 
<!DOCTYPE html>
<html lang="en">
<?php include 'head.php';?>
<!--<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link rel="stylesheet" href="styles.css">

    <script src="https://use.fontawesome.com/releases/v5.15.1/js/all.js" data-auto-replace-svg="nest"></script>

    <title>Attendance</title>-->
	
	<script type="text/javascript">
		window.history.forward();
		function noBack() { window.history.forward(); }
		//window.onbeforeunload = function() { return "You answer sheet will be lost."; };
		
		function reload(form){
			var val=form.board_id.options[form.board_id.options.selectedIndex].value;

			self.location='04-02_edit_prev_school_info.php?board_id=' + val ;
		}
		
		var myVar = setInterval(myTimer, 1000);

		function myTimer() {
		  var d = new Date();
		  var t = d.toLocaleTimeString();
		  document.getElementById("my-timer").innerHTML = t;
		}
		
		
	</script>
</head>

<body>
    <?php include 'header.php';?>

    <section>
        <div class="wrapper-box">
            <nav class="box-1 custom-scrollbar">
                <ul class="list">
					<div class="nav-head">
						<h4> Navigator </h4>
						<h4> (Main Menu) </h4>
					</div>
                    <li class="list-item"><a href="04_applicant_menu.php">Applicant Menu</a></li>
					<li class="list-item"><a href="index.php">Logout</a></li></a></li>
                </ul>
            </nav>
        
            <div class="main box-2 custom-scrollbar">
                <div class="main-body">
					<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
						<table style="width:98%">
						<tr>	
							<th>
								<div class="attendance">
								<span>Welcome <?php echo $name.'&nbsp &nbsp &nbsp[Applicant Code: '.$reg_code.']'; ?> </span>
								<span>
								<?php 
									if($photo == 1){
										
										if(is_file("upload/".$file_pho)){
											echo "<img src='upload/" . $file_pho . "'  width='25' height='30'>";
										}
										
									}else {
										echo 'Please upload your photo';
									}
								?>
								</span>	
								</div>
								</th>
						</tr>
						</table>
						
						<table style="width:98%">
						<tr>
							<td><?php echo $board; ?></td>
							<td><?php echo $school; ?></td>
							<td><?php echo $email; ?></td>
							<td><?php echo $mobile; ?></td>
							<td><?php echo $p_mobile; ?></td>
							
						</tr>
						</table>

						
						<br>
						<table style="width:98%">
						<tr>	
							<th>Educational Information:</th>
						</tr>
						</table>
						<table style="width:98%">
						
						<tr>	
							<td>Previous Board:<span  style="color:red"> *</span></td>
							
							
							<th>
								<?php
									$conn = OpenCon();
									
									
									$sql = "SELECT * FROM board WHERE id != '$board_id' AND active = 'A'";
									echo '<select name="board_id"><option value="'.$board_id.'">'.$board.'</option>';
									
									$result = mysqli_query ($conn, $sql)or die(mysqli_error($conn));
									if (mysqli_affected_rows($conn) > 0) {
										while($record = mysqli_fetch_array($result, MYSQLI_ASSOC)){
											echo  "<option value='$record[id]'>$record[value]</option>";
										}

									}
									echo "</select>";
									//echo '<span class="help-block">'.$board_err.'</span>';
									
									CloseCon($conn);
								?>
								
							</th>
						</tr>
						
						<tr>	
							<td>Previous School Name:<span  style="color:red"> *</span></td>
							
							<th>
								<input type="text" name="school" placeholder="School name" autocomplete="off" required value="<?php echo $school; ?>">
								<!--<span class="help-block"><?php //echo $prev_school_err;?></span>-->
							</th>
						</tr>
			
						division
						
						<tr>
							<td>Board Certificate no.:<span  style="color:red"> *</span></td>
							
							<th>
								<input type="text" name="certificate_no" placeholder="board registration no" autocomplete="off" required value="<?php echo $certificate_no; ?>">
									<!--<span class="help-block"><?php //echo $certificate_no_err;?></span>-->
							</th>
						</tr>	
						
						<tr>
							<td>Division :<span  style="color:red"> *</span></td>
							
							<th>
								<input type="text" name="division" placeholder="board division" autocomplete="off" required value="<?php echo $division; ?>">
									<!--<span class="help-block"><?php //echo $certificate_no_err;?></span>-->
							</th>
						</tr>
						
						</table>
		
						<?php
							
							echo '<button type="submit" name="submit" value="submit" class="btn">Update School Information</button>';
							
						?>
						
						
					</form>
						
					
				</div>
            </div>
        
            <?php include 'information.php';?>
        </div>
    </section>

    
    <?php include 'footer.php';?>

    <script src="app.js"></script>
</body>
</html>